package com.example.mobile2021606163crw0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private Button btnReset;
    private TextView tvMainQuestion1;
    private RadioGroup rdgDemo1;
    private RadioButton Radbtn1A;
    private RadioButton Radbtn1B;
    private RadioButton Radbtn1C;
    private RadioButton Radbtn1D;
    private TextView tvMainQuestion2;
    private RadioGroup rdgDemo2;
    private RadioButton Radbtn2A;
    private RadioButton Radbtn2B;
    private RadioButton Radbtn2C;
    private RadioButton Radbtn2D;
    private TextView tvMainQuestion3;
    private RadioGroup rdgDemo3;
    private RadioButton Radbtn3A;
    private RadioButton Radbtn3B;
    private RadioButton Radbtn3C;
    private RadioButton Radbtn3D;
    private TextView tvMainQuestion4;
    private RadioGroup rdgDemo4;
    private RadioButton Radbtn4A;
    private RadioButton Radbtn4B;
    private RadioButton Radbtn4C;
    private RadioButton Radbtn4D;
    private Button btnSubmit;
    private TextView tvEnd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        rdgDemo1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        rdgDemo2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        rdgDemo3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        rdgDemo4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int optionID1 = rdgDemo1.getCheckedRadioButtonId();
                int optionID2 = rdgDemo2.getCheckedRadioButtonId();
                int optionID3 = rdgDemo3.getCheckedRadioButtonId();
                int optionID4 = rdgDemo4.getCheckedRadioButtonId();
                if (optionID1 == R.id.Radbtn1A & optionID2==R.id.Radbtn2B & optionID3==R.id.Radbtn3B & optionID4==R.id.Radbtn4C) {
                    tvEnd.setText("分数：100分");
                } else if (optionID1 == R.id.Radbtn1A & optionID2==R.id.Radbtn2C & optionID3==R.id.Radbtn3B || optionID2==R.id.Radbtn2C & optionID3==R.id.Radbtn3B & optionID4==R.id.Radbtn4A || optionID1 == R.id.Radbtn1A& optionID3==R.id.Radbtn3B & optionID4==R.id.Radbtn4A) {
                    tvEnd.setText("分数：75分");
                }else if (optionID1 == R.id.Radbtn1A & optionID2==R.id.Radbtn2C || optionID1 == R.id.Radbtn3B& optionID3==R.id.Radbtn3B||optionID1 == R.id.Radbtn1A& optionID4==R.id.Radbtn4A|| optionID2==R.id.Radbtn2C & optionID3==R.id.Radbtn3B|| optionID2==R.id.Radbtn2C & optionID4==R.id.Radbtn4A|| optionID3==R.id.Radbtn3B & optionID4==R.id.Radbtn4A){
                    tvEnd.setText("分数：50分");
                }else if (optionID1 == R.id.Radbtn1A  || optionID2==R.id.Radbtn2C  || optionID3==R.id.Radbtn3B || optionID4==R.id.Radbtn4A){
                    tvEnd.setText("分数：25分");
                }else if (optionID1==-1||optionID2==-1||optionID3==-1||optionID4==-1 ){
                    Toast.makeText(MainActivity.this, "请作出选择", Toast.LENGTH_SHORT).show();
                }else{
                    tvEnd.setText("分数：0分");
                }
            }

        });
        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Radbtn1A.setChecked(false);
                Radbtn1B.setChecked(false);
                Radbtn1C.setChecked(false);
                Radbtn1D.setChecked(false);
                Radbtn2A.setChecked(false);
                Radbtn2B.setChecked(false);
                Radbtn2C.setChecked(false);
                Radbtn2D.setChecked(false);
                Radbtn3A.setChecked(false);
                Radbtn3B.setChecked(false);
                Radbtn3C.setChecked(false);
                Radbtn3D.setChecked(false);
                Radbtn4A.setChecked(false);
                Radbtn4B.setChecked(false);
                Radbtn4C.setChecked(false);
                Radbtn4D.setChecked(false);
                tvEnd.setText("");
                Toast.makeText(MainActivity.this,"重置完成",Toast.LENGTH_SHORT).show();

            }
        });


    }
    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnReset = (Button) findViewById(R.id.btn_Reset);
        tvMainQuestion1 = (TextView) findViewById(R.id.tv_main_question1);
        rdgDemo1 = (RadioGroup) findViewById(R.id.rdg_demo1);
        Radbtn1A = (RadioButton) findViewById(R.id.Radbtn1A);
        Radbtn1B = (RadioButton) findViewById(R.id.Radbtn1B);
        Radbtn1C = (RadioButton) findViewById(R.id.Radbtn1C);
        Radbtn1D = (RadioButton) findViewById(R.id.Radbtn1D);
        tvMainQuestion2 = (TextView) findViewById(R.id.tv_main_question2);
        rdgDemo2 = (RadioGroup) findViewById(R.id.rdg_demo2);
        Radbtn2A = (RadioButton) findViewById(R.id.Radbtn2A);
        Radbtn2B = (RadioButton) findViewById(R.id.Radbtn2B);
        Radbtn2C = (RadioButton) findViewById(R.id.Radbtn2C);
        Radbtn2D = (RadioButton) findViewById(R.id.Radbtn2D);
        tvMainQuestion3 = (TextView) findViewById(R.id.tv_main_question3);
        rdgDemo3 = (RadioGroup) findViewById(R.id.rdg_demo3);
        Radbtn3A = (RadioButton) findViewById(R.id.Radbtn3A);
        Radbtn3B = (RadioButton) findViewById(R.id.Radbtn3B);
        Radbtn3C = (RadioButton) findViewById(R.id.Radbtn3C);
        Radbtn3D = (RadioButton) findViewById(R.id.Radbtn3D);
        tvMainQuestion4 = (TextView) findViewById(R.id.tv_main_question4);
        rdgDemo4 = (RadioGroup) findViewById(R.id.rdg_demo4);
        Radbtn4A = (RadioButton) findViewById(R.id.Radbtn4A);
        Radbtn4B = (RadioButton) findViewById(R.id.Radbtn4B);
        Radbtn4C = (RadioButton) findViewById(R.id.Radbtn4C);
        Radbtn4D = (RadioButton) findViewById(R.id.Radbtn4D);
        btnSubmit = (Button) findViewById(R.id.btn_submit);
        tvEnd = (TextView) findViewById(R.id.tv_end);
    }
}